// RMSServerDlg.h : header file
//

#if !defined(AFX_RMSSERVERDLG_H__B2082D5E_C1D5_4FAA_A346_440941A4F9A1__INCLUDED_)
#define AFX_RMSSERVERDLG_H__B2082D5E_C1D5_4FAA_A346_440941A4F9A1__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

/////////////////////////////////////////////////////////////////////////////
// CRMSServerDlg dialog
#include "RMSBaseServer.h"
#include "../Lib/BtnST.h"	// tansparent button & bitmaps

#include "../Lib/RMSHostEnt.h"

#include "../GUI/MegaDialog.h"
#include "../GUI/MegaDialogNvc.h"
#include "../GUI/MegaBitmap.h"
#include "../GUI/MegaListBox.h"
#include "MegaDrawerPrefs.h"
#include "SetParametersDlg.h"

extern BYTE* pSleepBitmapData;
extern BYTE* pSleepBitmapDataCompressed;
extern int sizeSleepCompressed;

extern bool gUserModeEnabled;

#ifdef _IPR_
  extern bool gEnableIpr;
#endif //def _IPR_

#ifdef _NET_VC_
	#define IDD_THIS_DIALOG		IDD_PERSONAL_VCENCODER_DIALOG
	#define MEGA_DIALOG			CMegaDialogNvc
#else //def _NET_VC_
	#ifdef _QFI_
	#define IDD_THIS_DIALOG		IDD_RMSSERVER_DIALOGQFI 
	#elif _VITAL_
	#define IDD_THIS_DIALOG		IDD_RMSSERVER_DIALOGVITAL
	#else
	#define IDD_THIS_DIALOG		IDD_RMSSERVER_DIALOG 
	#endif
	#define MEGA_DIALOG			CMegaDialog
#endif //def _NET_VC_


class MPoint : public CPoint
{
public:
	void SetPoint(int nx, int ny) { x = nx; y = ny; };
};


class CRMSServerDlg : public MEGA_DIALOG
{
// Construction
public:
	CBaseServer BaseServer;

	enum STATUS
	{
		AUDIO_STATUS_NONE	=	0,
		AUDIO_STATUS_PLAY	=	1,
		AUDIO_STATUS_BUFFERING	= 2,
		AUDIO_STATUS_DISABLE	= 3,
		AUDIO_STATUS_ACTIVE		= 4,

		VIDEO_STATUS_NONE	=	5,
		VIDEO_STATUS_PLAY	=	6,
		VIDEO_STATUS_BUFFERING	= 7,
		VIDEO_STATUS_DISABLE	= 8,
		VIDEO_STATUS_ACTIVE		= 9,


	};
	void SetAudioStatus(STATUS nStatus);
	void SetVideoStatus(STATUS nStatus);

	CString	m_homePath;
	void initHomePath();
	LPCTSTR getHomePath();
	void saveHomePath(LPCTSTR home);

	CTime	m_time;
	CString m_strTime, m_strDate;

	RMSHostEnt m_host;

	// sleep mode, 1- no video/audio capture is performed
	// switched off on pickup
	int		SleepMode;
	int		*pSzAudio;
	int		*pSzVideo;
	int		*pSzDate;
	int		*pSzTime;
	BYTE    *dtAudio;
	BYTE    *dtVideo;
	BYTE    *dtDate;
	BYTE    *dtTime;

	CRITICAL_SECTION *pCriticalData;
	CRITICAL_SECTION *pCriticalAudio;

	BOOL m_bAudio, m_bVideo;
	BOOL m_AudioDevicePresent;
	BOOL m_VideoDevicePresent;
	BOOL m_bMove, m_Dragable;
	CPoint m_moveCursorPos, m_moveOffset;
	int	 m_nCurrentFPS;
	HWND mainHandle;

	void ShowInfoBar();
	void ShowClientCount();
	void MoveControl(int ID, int x,int y);

	void SetControlSize(int ID, int w,int h);
	int  GetControlY(int ID);
	int  GetControlW(int ID);
	int  GetControlH(int ID);

	CRMSServerDlg(CWnd* pParent = NULL);	// standard constructor
	void UpdateServer(const char *szIP, UINT nPort);
	void StartLive();
	void StopLive();
    bool InitOutput(bool);
	void SetCustomImage();
	void UpdateFeedStatus();

protected:
	CRect m_rcPreview;
	int m_nInfoBarHeight;

#ifdef _GUI2008_
  CMenu SettingsMenu;
#endif


#ifdef _NET_VC_
	CRect m_rcInfoBar;
	CRect m_rcClientsList;
	MPoint m_ptClientCounter;
	MPoint m_ptEncoderLogo;
	MPoint m_ptStartViewer;
#ifdef _GUI2008_
    MPoint m_ptHi;
	MPoint m_ptLow;
#else
    MPoint m_ptVideoSource;
    MPoint m_ptSetParameters;
    MPoint m_ptCast;
	MPoint m_ptConf;
    CMegaButton m_btnVideoSource, m_btnSetParameters;
#endif
	MPoint m_ptVideo;
	MPoint m_ptAudio;
	MPoint m_ptExit;
	CMegaButton m_btnWinMinimize, m_btnWinClose; 
	MPoint m_ptWinMinimize, m_ptWinClose;
    CMegaButton m_btnExit,m_btnSetting;//,m_btnWinMinimize, m_btnWinClose; //charith 21-05-2015
	CSetParametersDlg m_spDlg;
	CMegaButton m_btnDlgIcon;

	HANDLE m_hMutex;
	CString m_addr;
#endif //def _NET_VC_

	CMegaDrawerPrefs m_PrefDrawer;
	CMegaBitmap m_EncoderLogo, m_SBXLogo, m_SBXLogoSmall;
	CMegaBitmap m_PartnerLogo;

	CMegaButton m_VideoBtn, m_AudioBtn, m_SleepBtn, m_StartViewerBtn;
    
#ifdef _GUI2008_
    CMegaButton m_btnHi, m_btnLow;
#else
    CMegaButton m_btnCast, m_btnConf;
#endif

	HRGN m_hrgnVideo, m_hrgnAudio, m_hrgnSleep;

	CMegaListBox m_ClientsList;
	bool m_bEnableBroadcast;

#ifdef _TEC_
	HANDLE m_hGlobal;
	BOOL createGlobal();
#endif //def _TEC_

	// server params
public:
	int m_nPort;
	CString m_strIP;

public:

// Dialog Data
	//{{AFX_DATA(CRMSServerDlg)
	enum { IDD = IDD_THIS_DIALOG };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CRMSServerDlg)
	public:
	virtual void OnDestroy();
	virtual BOOL DestroyWindow();
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
private:
	void DisableVideoButtons();
	void CallViewer(LPCTSTR lpaddr);
	BOOL bWasSetStillImage;

	int Call_Ok;

#ifdef _J707_ 
	//#J7070021
	LRESULT SaveLowMode();
	//#J7070022
	LRESULT SaveEncoderParam();
	LRESULT LoadEncoderParam();
#endif

protected:
	HICON m_hIcon;
    bool SettingsMenuAvailable;

    int ChangeBitsAndFps(int bitsperframe, int fps);
    void EnableSettingsMenu();

	// Generated message map functions
	//{{AFX_MSG(CRMSServerDlg)
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point); //charith 21-05-2015
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);//charith 21-05-2015
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);// charith 25-05-2015
	afx_msg void OnNcRButtonDown(UINT nFlags, CPoint point);// charith 25-05-2015
	afx_msg UINT OnNcHitTest(CPoint point);
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnSetserver();
	afx_msg void OnSave();
	afx_msg void OnSound();
	afx_msg void OnVideo();
	afx_msg void OnClose();
	afx_msg void OnIDCMinimize();
	afx_msg void OnExit();
	afx_msg void OnPassword();
	afx_msg void OnHelp();
	afx_msg LRESULT OnCall(WPARAM wparam, LPARAM lparam);
	afx_msg void OnVC10();
	afx_msg void OnSelchangeClients();
	afx_msg void OnDblclkClients();
	afx_msg void OnSleep();
	afx_msg void OnIconClick();

#ifdef _GUI2008_
    afx_msg void OnHi();
	afx_msg void OnLow();
#endif
	afx_msg void OnCast();
	afx_msg void OnConf();

	afx_msg void OnVideoSource();
	afx_msg void OnSetParameters();
	afx_msg void OnExitButton();

	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg LRESULT OnSelectVideoSource(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnChangeServerParams(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnChangeCyclicBuffer(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnChangeHomePath(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnChangePassword(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnChangeBitrate(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnChangeFPS(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnChangeSize(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnNewClientConnected(WPARAM wParam, LPARAM lParam);
	
	afx_msg LRESULT User_Message(WPARAM wParam, LPARAM lParam);
  #ifdef _IPR_
	afx_msg LRESULT OnRegistIP(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnUnregistIP(WPARAM wParam, LPARAM lParam);
  #endif //def _IPR_
	
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

	BOOL DropPopupMenu(UINT nFlags, CPoint point);
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_RMSSERVERDLG_H__B2082D5E_C1D5_4FAA_A346_440941A4F9A1__INCLUDED_)
